/**
采购商的首页統計信息
author:songhlc
*/
define(["jquery","knockout","baseview","common","echarts"],function($,ko,BaseView,Common,echarts){
	var self;
    var view = BaseView.extend({
		setTemplate: function(option) {
		},
		bindEvents: function() {
		},
		fireEvents: function() {         
            self = this;
            /*加载datatable数据*/
            this.app.serverEvent().addDataTable("pustatisticDataTable").fire({
                url: "/yuncai/evt/dispatch",
                ctrl: "portal.PuStatisticController",
                method: 'queryData',
                success: function (data) {
                    var _data = eval('('+data+')');
                    $('#requirelist').attr({ href: '#/pages/requirement/requirelist/'+_data.currentUserRole.currentUserRole });
                    self.bindCharts();
                }
            });
        },
        viewmodel:{
            el:"#lineChart",
            pustatisticDataTable:new $.DataTable({
                params: {
                    "cls": "com.yonyou.yuncai.cpu.portal.view.PuStatisticView"
                },
                meta: {
                    'puAmouts': {}
                },
                pageSize: 10
            }),
        },
        bindCharts:function() {
            option = {
                title : {
                    text: window.i18next.t('home.pustatistic'),
                    subtext: '',
                    textStyle:{
                        fontSize:'16',
                        color:'#3333',
                        fontWeight:'normal',
                        fontFamily:'tahoma,arial,"Hiragino Sans GB", "Microsoft YaHei", "\5b8b\4f53"'
                    },
                    padding: 15
                },
                tooltip : {
                    trigger: 'axis'
                },
                legend: {
//                  data:['采购金额'],
//                  padding:15
                },
                toolbox: {
                    show : true,
                    feature : {
                        dataView : {show: false, readOnly: false},
                        magicType : {show: true, type: ['line', 'bar']},
                        restore : {show: false},
                        saveAsImage : {show: true}
                    }
                },
                calculable : true,
                xAxis: [{
                    type : 'category',
                    data : [window.i18next.t('home.January'),
                            window.i18next.t('home.February'),
                            window.i18next.t('home.March'),
                            window.i18next.t('home.April'),
                            window.i18next.t('home.May'),
                            window.i18next.t('home.June'),
                            window.i18next.t('home.July'),
                            window.i18next.t('home.August'),
                            window.i18next.t('home.September'),
                            window.i18next.t('home.October'),
                            window.i18next.t('home.November'),
                            window.i18next.t('home.December')]
                }],
                yAxis: [{
                    type : 'value'
                }],
                series : [
                    {
                        name: window.i18next.t('home.purchasemoney'),
                        type:'bar',
                        data:self.viewmodel.pustatisticDataTable.getCurrentRow().getValue("puAmouts"),
                        markPoint : {
                            data : [
                                {type : 'max', name: window.i18next.t('home.max')},
                                {type : 'min', name: window.i18next.t('home.min')}
                            ],
                            label:{
                                normal:{
                                    show:true,
                                    textStyle:{
                                        color:'#676a6c'
                                    }
                                }
                            }
                        },
                        itemStyle:{
                            normal:{
                                color:'#eb525d'
                            }
                        }
                    }
                ]
            };

            var myChart = echarts.init(document.getElementById('lineChart'));
            myChart.setOption(option);
        }
	});
	return view;
});
